package com.ssy.lingxi.member.merchant.model.bo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 解析Excel文件返回的内容
 * @author 万宁
 * @version 2.0.0
 * @date 2020-07-18
 */
public class ExcelFileContentBO implements Serializable {
    private static final long serialVersionUID = 7117989099382761330L;

    public ExcelFileContentBO() {
        fieldCount = 0;
        rowCount = 0;
        headers = new ArrayList<>();
        contents = new ArrayList<>();
    }

    /**
     * 列数
     */
    private Integer fieldCount;

    /**
     * 行数
     */
    private Integer rowCount;

    /**
     * 标题行
     */
    private List<CellItem> headers;

    /**
     * 内容行
     */
    private List<CellItem> contents;

    @Override
    public String toString() {
        String summary = "行数：" + rowCount.toString() + " 列数：" + fieldCount.toString() + "\r";
        String header = headers.stream().map(CellItem::getFieldValue).collect(Collectors.joining(","));
        String fields = contents.stream().map(c -> c.getRowNo().toString() + " " + c.getFieldNo() + " => " + c.getFieldValue()).collect(Collectors.joining("\r"));
        return summary + "\r" + header + "\r" + fields;
    }

    public Integer getFieldCount() {
        return fieldCount;
    }

    public void setFieldCount(Integer fieldCount) {
        this.fieldCount = fieldCount;
    }

    public Integer getRowCount() {
        return rowCount;
    }

    public void setRowCount(Integer rowCount) {
        this.rowCount = rowCount;
    }

    public List<CellItem> getHeaders() {
        return headers;
    }

    public void setHeaders(List<CellItem> headers) {
        this.headers = headers;
    }

    public List<CellItem> getContents() {
        return contents;
    }

    public void setContents(List<CellItem> contents) {
        this.contents = contents;
    }

    public static class CellItem {

        /**
         * 行序号，标题行为0，内容行从1开始
         */
        private Integer rowNo;

        /**
         * 列序号，从1开始
         */
        private Integer fieldNo;

        /**
         * CELL的内容
         */
        private String fieldValue;

        public Integer getRowNo() {
            return rowNo;
        }

        public void setRowNo(Integer rowNo) {
            this.rowNo = rowNo;
        }

        public Integer getFieldNo() {
            return fieldNo;
        }

        public void setFieldNo(Integer fieldNo) {
            this.fieldNo = fieldNo;
        }

        public String getFieldValue() {
            return fieldValue;
        }

        public void setFieldValue(String fieldValue) {
            this.fieldValue = fieldValue;
        }
    }
}
